import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;


public class PresmetuvanjePerioda {

	public static int broj_na_kvazigrupi=51;
	public static int[] quasigroupNumber= {174, 186, 189, 448, 449, 464, 482, 494, 496, 523, 688, 698, 732, 737, 804, 974, 1001, 1144, 1533, 1582, 1968, 2324, 2364, 3014, 3047, 3133, 3163, 3169, 3701, 3708, 3837, 3916, 4111, 4602, 4613, 4684, 4854, 5035, 5071, 5086, 5318, 5326, 5332, 5683, 5685, 5741, 5764, 5811, 5862, 5898, 5916, 5975};
	
	public int perioda(String str)
	{		  
		  int izlez=0;
		  int br=2;
		  boolean b=true;
		  String str1="",str2="";
		  
		  while(br<str.length()/2){
		   str1=str.substring(10, 10+br);
		   b=true;
		   for(int i=1;(i+1)*br+10<str.length();i++){
		   str2=str.substring(10+i*br, 10+(i+1)*br);
		   if(!str1.equals(str2)){
		    b=false;
		    break;
		   }
		   }
		   if(b){
		    izlez=br;
		    break;
		   }
		   else
		    br++;
		  }
		  return izlez;
		 }
  
  public void presmetajPeriodi() throws IOException
  {
  	BufferedWriter writer = new BufferedWriter(new FileWriter("periodi.txt"));
  	String content="";
  	
  	for (int i = 1; i <= broj_na_kvazigrupi; i++)
      {
  		try
  		{
	    		BufferedReader reader1=new BufferedReader(new FileReader("datoteki\\q"+quasigroupNumber[i]+".txt"));
	    		
	    		String text1=reader1.readLine();
	    		
	    		int p1=0,p2=0,p3=0;
	    		
	    		int count=1;
	    		p1=perioda(text1.substring(0));
	    		//System.out.println(p1);
	    		while(p1>=21000)
	    		{
	    			//System.out.println(count);
	    			p1=perioda(text1.substring(count));
	    			count++;
	    			if(count>1000)
	    			{
	    				break;
	    			}
	    		}
	    		
	    		System.out.println(p1);
	    		content+=p1+"\n";
	    		
	    		reader1.close();
	    }
  		catch(Exception e)
  		{
  			System.out.println(i);
  		}
      }
  	
  	writer.write(content);
  	writer.close();
  }

  public static void main(String[] args) throws IOException
  {
	  PresmetuvanjePerioda p = new PresmetuvanjePerioda();
	  p.presmetajPeriodi();
  }

}
